package com.sunyard.utils.manage;

import com.github.pagehelper.PageInfo;


import java.util.List;

/**
 * @description: 取分页信息工具类
 * @author: DUANYUBIN
 * @create: 2020-07-31 15:22
 **/
public class PageQuery {

    public static <T> DataGrid<T> getDataGrid(List<T> list) {
        // 取分页信息
        PageInfo<T> pageInfo = new PageInfo<T>(list);
        // 设置返回结果
        DataGrid<T> dataGrid = new DataGrid<>();
        Long total = pageInfo.getTotal();
        int pageNum = pageInfo.getPageNum();
        dataGrid.setTotal(total.intValue());
        dataGrid.setRows(list);
        dataGrid.setPageNum(pageNum);
        return dataGrid;
    }

    /**
     * 对数据进行分页
     *
     * @param totalList 原分页查询获取到的list
     * @param dataList  返回的到前端的list
     * @return com.syd.cipss.util.common.util.DataGrid
     * @author: guangw.dang
     * @Date: 2022/3/16 14:42
     **/
    public static DataGrid getDataGrids(List totalList, List dataList) {
        // 取分页信息
        PageInfo pageInfo = new PageInfo<>(totalList);
        // 设置返回结果
        DataGrid dataGrid = new DataGrid<>();
        Long total = pageInfo.getTotal();
        dataGrid.setTotal(total.intValue());
        dataGrid.setRows(dataList);
        return dataGrid;
    }
}
